﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using IBM.Data.DB2;
using System.Text;

public partial class caselist : System.Web.UI.Page
{
    protected string EasyUIDataGridIntialData;
    protected string InitialUrl;
    protected string TableTitle;
    protected string WebPageName;
    protected string[,] DataGirdColumns;
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Buffer = false;
        Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
        Response.Expires = 0;
        Response.CacheControl = "no-cache";  

        WebPageName = Request.QueryString["webpagename"];
        int count = Request.QueryString.Count;
        string tempstr = "";
        for (int i = 0; i < count; i++)
        {
            tempstr += "&" + Request.QueryString.AllKeys[i] + "=" + Server.UrlEncode(Request.QueryString.GetValues(i)[0]);

        }
        InitialUrl = string.Format("url:'caselist_handler.ashx?{0}',", tempstr);
        if (WebPageName != null)
        {
            switch (WebPageName.ToLower().Trim())
            {
                //case "index":
                //case "zxqk":
                //case "jal":
                //case "jal_ms":
                //case "jal_xs":
                //case "jal_xz":
                //case "jal_zx":
                //case "jal_ss":
                //case "jal_ss2":
                //case "jal_ms_ss":
                //case "jal_xs_ss":
                //case "jal_xz_ss":
                //case "jal_zx_ss":
                //case "xqfy_ms_ajay_fx":
                //case "xqfy_xs_ajay_fx":
                //case "xqfy_xz_ajay_fx":
                //case "xqfy_ms_ajay_fx_zdy":
                //case "xqfy_xs_ajay_fx_zdy":
                //case "xqfy_xz_ajay_fx_zdy":
                case "zxgztj_pg":
                    ZXTJGZ();
                    break;
                case "zxgztj_bm":
                    ZXTJGZ();
                    break;
                case "zxgztj_cf":
                    ZXTJGZ();
                    break;
                case "zxgztj_dj":
                    ZXTJGZ();
                    break;
                case "zxgztj_fk":
                    ZXTJGZ();
                    break;
                case "zxgztj_jl":
                    ZXTJGZ();
                    break;
                case "zxgztj_ky":
                    ZXTJGZ();
                    break;
                case "zxgztj_pm":
                    ZXTJGZ();
                    break;
                case "zxgztj_xz":
                    ZXTJGZ();
                    break;
                case "zxgztj_lx":
                    ZXTJGZ();
                    break;
                case "zxgztj_fzys":
                    ZXTJGZ();
                    break;
                case "zxgztj_blkf":
                    ZXTJGZ();
                    break;
                
                //case "xcxk":
                //    JAL();
                //    break;
                //case "ljfygxajcxxt":
                //case "lyssqccx":
                //    AJ("案件查询", "查询结果", false);
                //    break;

                //case "zhtjfx":
                //    AJ("案件统计", "统计结果", true);
                //    break;
                default: break;

            }
        }

    }

    protected void JAL()
    {
        Title = "案件反查";
        DataGirdColumns = new string[8, 4];
        int columnsIndexx = 0;

        DataGirdColumns[columnsIndexx, 0] = "AH"; DataGirdColumns[columnsIndexx, 1] = "案号"; DataGirdColumns[columnsIndexx, 2] = "150"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "LARQ"; DataGirdColumns[columnsIndexx, 1] = "立案日期"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "GRO_AJZT"; DataGirdColumns[columnsIndexx, 1] = "案件主题"; DataGirdColumns[columnsIndexx, 2] = "400"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "UISFAY"; DataGirdColumns[columnsIndexx, 1] = "统计案由"; DataGirdColumns[columnsIndexx, 2] = "150"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "CBSPT"; DataGirdColumns[columnsIndexx, 1] = "承办庭"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "UICBR"; DataGirdColumns[columnsIndexx, 1] = "承办人"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "JARQ"; DataGirdColumns[columnsIndexx, 1] = "结案日期"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "AHZT"; DataGirdColumns[columnsIndexx, 1] = "案号字头"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "true"; columnsIndexx++;
       
        string fydm = Request.QueryString["fydm"];
        StringBuilder JsBuilder = new StringBuilder();
        JsBuilder.AppendLine("title:'查询结果',");
        JsBuilder.AppendLine("//height:350,");
        JsBuilder.AppendLine("nowrap: true ,");
        JsBuilder.AppendLine("rownumbers: true,");
        JsBuilder.AppendLine("animate:true,");
        JsBuilder.AppendLine("singleSelect:true,");
        JsBuilder.AppendLine("collapsible:true,");
        JsBuilder.AppendLine("collapsible:true,");
        JsBuilder.AppendLine(InitialUrl);
        JsBuilder.AppendLine(" sortName: 'AH',");
        JsBuilder.AppendLine("sortOrder: 'desc',");
        JsBuilder.AppendLine("remoteSort: true ,");
        JsBuilder.AppendLine("pagination: true,");
        JsBuilder.AppendLine("pageSize: 30,");
        JsBuilder.AppendLine("columns:[[");
        int count = DataGirdColumns.GetLength(0);
        for (int i = 0; i < count; i++)
        {
            JsBuilder.AppendLine(string.Format("{{field:\"{0}\",title:\"{1}\",width:{2},hidden:{3},sortable:true}},", DataGirdColumns[i, 0], DataGirdColumns[i, 1], DataGirdColumns[i, 2], DataGirdColumns[i, 3]));
        }
        JsBuilder.AppendLine("{field:\"\",title:\"\",hidden:true}");
        JsBuilder.AppendLine("]],");
        JsBuilder.AppendLine("onDblClickRow:function(rowIndex, row){");
        JsBuilder.AppendLine(" if (row[\"AH\"]==\"\") return;");
        JsBuilder.AppendLine(string.Format(" OpenCase(row[\"AH\"],'{0}',row[\"AHZT\"]);", fydm));
        JsBuilder.AppendLine("}");
        EasyUIDataGridIntialData = JsBuilder.ToString();
    }

    protected void ZXTJGZ()
    {
        Title = "案件反查";
        DataGirdColumns = new string[8, 4];
        int columnsIndexx = 0;
        
        DataGirdColumns = JsonstringFC.JsonStrCol(WebPageName);

        string fydm = Request.QueryString["fydm"];
        StringBuilder JsBuilder = new StringBuilder();
        JsBuilder.AppendLine("title:'查询结果',");
        JsBuilder.AppendLine("//height:350,");
        JsBuilder.AppendLine("nowrap: true ,");
        JsBuilder.AppendLine("rownumbers: true,");
        JsBuilder.AppendLine("animate:true,");
        JsBuilder.AppendLine("singleSelect:true,");
        JsBuilder.AppendLine("collapsible:true,");
        JsBuilder.AppendLine("collapsible:true,");
        JsBuilder.AppendLine(InitialUrl);
        JsBuilder.AppendLine(" sortName: 'AJBH',");
        JsBuilder.AppendLine("sortOrder: 'desc',");
        JsBuilder.AppendLine("remoteSort: true ,");
        JsBuilder.AppendLine("pagination: true,");
        JsBuilder.AppendLine("pageSize: 30,");
        JsBuilder.AppendLine("columns:[[");
        int count = DataGirdColumns.GetLength(0);
        for (int i = 0; i < count; i++)
        {
            JsBuilder.AppendLine(string.Format("{{field:\"{0}\",title:\"{1}\",width:{2},hidden:{3},sortable:true}},", DataGirdColumns[i, 0], DataGirdColumns[i, 1], DataGirdColumns[i, 2], DataGirdColumns[i, 3]));
        }
        JsBuilder.AppendLine("{field:\"\",title:\"\",hidden:true}");
        JsBuilder.AppendLine("]],");
        JsBuilder.AppendLine("onDblClickRow:function(rowIndex, row){");
        JsBuilder.AppendLine(" if (row[\"AJBH\"]==\"\") return;");
        JsBuilder.AppendLine(string.Format(" OpenCase(row[\"AJBH\"],'{0}',row[\"AHZT\"]);", fydm));
        JsBuilder.AppendLine("}");
        EasyUIDataGridIntialData = JsBuilder.ToString();
    }

    protected void AJ(string pagetitle, string tabletitle, bool displayResultTitle)
    {
        Title = pagetitle;
        DataGirdColumns = new string[12, 4];
        int columnsIndexx = 0;
        DataGirdColumns[columnsIndexx, 0] = "XML_FYMC"; DataGirdColumns[columnsIndexx, 1] = "法院"; DataGirdColumns[columnsIndexx, 2] = "150"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_FYDM"; DataGirdColumns[columnsIndexx, 1] = "法院代码"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "true"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_AH"; DataGirdColumns[columnsIndexx, 1] = "案号"; DataGirdColumns[columnsIndexx, 2] = "150"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_UIRXAJLX"; DataGirdColumns[columnsIndexx, 1] = "案件类型"; DataGirdColumns[columnsIndexx, 2] = "150"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_GROAJZT"; DataGirdColumns[columnsIndexx, 1] = "案件主题"; DataGirdColumns[columnsIndexx, 2] = "150"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_CBSPTMC"; DataGirdColumns[columnsIndexx, 1] = "审判庭"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_UICBR"; DataGirdColumns[columnsIndexx, 1] = "主审人"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_LARQ"; DataGirdColumns[columnsIndexx, 1] = "立案日期"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_JARQ"; DataGirdColumns[columnsIndexx, 1] = "结案日期"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_JAFS"; DataGirdColumns[columnsIndexx, 1] = "结案方式"; DataGirdColumns[columnsIndexx, 2] = "120"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_AHZT"; DataGirdColumns[columnsIndexx, 1] = "案号字头"; DataGirdColumns[columnsIndexx, 2] = "80"; DataGirdColumns[columnsIndexx, 3] = "true"; columnsIndexx++;
        DataGirdColumns[columnsIndexx, 0] = "XML_UISJY"; DataGirdColumns[columnsIndexx, 1] = "书记员"; DataGirdColumns[columnsIndexx, 2] = "120"; DataGirdColumns[columnsIndexx, 3] = "false"; columnsIndexx++;

        string fydm = Request.QueryString["fydm"];
        StringBuilder JsBuilder = new StringBuilder();
        JsBuilder.AppendLine(string.Format("title:'{0}',", tabletitle));
        JsBuilder.AppendLine("//height:350,");
        JsBuilder.AppendLine("nowrap: true ,");
        JsBuilder.AppendLine("rownumbers: true,");
        JsBuilder.AppendLine("animate:true,");

        JsBuilder.AppendLine("singleSelect:true,");
        JsBuilder.AppendLine("collapsible:true,");
        JsBuilder.AppendLine("collapsible:true,");
        JsBuilder.AppendLine(InitialUrl);
        JsBuilder.AppendLine(" sortName: 'XML_AH',");
        JsBuilder.AppendLine("sortOrder: 'desc',");
        JsBuilder.AppendLine("remoteSort: true ,");
        JsBuilder.AppendLine("pagination: true,");
        JsBuilder.AppendLine("pageSize: 30,");
        if (displayResultTitle)
        {
            JsBuilder.AppendLine("onLoadSuccess:function (data){");
            JsBuilder.AppendLine("$('#tqdbSpan').css(\"display\",\"inline\");");
            JsBuilder.AppendLine("var cc=$('#SFTQDB',window.parent.document).val();");
            JsBuilder.AppendLine("if(cc!=null){");


            JsBuilder.AppendLine("  if(cc!=\"1\"){");
            JsBuilder.AppendLine("       $.get(\"LYSSQCCX_Handler.ashx?method=get_count\", { Action: \"get\", Name: \"lulu\" }, function(datax, textStatus) {");
            JsBuilder.AppendLine("var fff=datax.toString();");
            JsBuilder.AppendLine(" $('#tqdbSpan').html(fff);");

            JsBuilder.AppendLine(" });");
            JsBuilder.AppendLine("     return ;}");
            JsBuilder.AppendLine("}");
            JsBuilder.AppendLine(" else ");
            JsBuilder.AppendLine(" {");
            JsBuilder.AppendLine("   if(getParam(\"SFTQDB\")!=\"1\")");
            JsBuilder.AppendLine(" { ");
            JsBuilder.AppendLine(" $.get(\"LYSSQCCX_Handler.ashx?method=get_count\", { Action: \"get\", Name: \"lulu\" }, function(datax, textStatus) {");
            JsBuilder.AppendLine(" var fff=datax.toString();");
            JsBuilder.AppendLine("  $('#tqdbSpan').html(fff);");

            JsBuilder.AppendLine(" });");
            JsBuilder.AppendLine("   return ;");
            JsBuilder.AppendLine("    }");
            JsBuilder.AppendLine("}");
            JsBuilder.AppendLine("$.get(\"LYSSQCCX_Handler.ashx?method=get_tqdb_count\", { Action: \"get\", Name: \"lulu\" }, function(datax, textStatus) {");
            JsBuilder.AppendLine("  var fff=datax.toString();");
            JsBuilder.AppendLine("   $('#tqdbSpan').html(fff);");

            JsBuilder.AppendLine("});");
            JsBuilder.AppendLine(" },");
        }
        JsBuilder.AppendLine("  onLoadError:function(){$('#tqdbSpan').css(\"display\",\"none\");},");
        JsBuilder.AppendLine("columns:[[");
        int count = DataGirdColumns.GetLength(0);
        for (int i = 0; i < count; i++)
        {
            JsBuilder.AppendLine(string.Format("{{field:\"{0}\",title:\"{1}\",width:{2},hidden:{3},sortable:true}},", DataGirdColumns[i, 0], DataGirdColumns[i, 1], DataGirdColumns[i, 2], DataGirdColumns[i, 3]));
        }
        JsBuilder.AppendLine("{field:\"\",title:\"\",hidden:true}");
        JsBuilder.AppendLine("]],");
        JsBuilder.AppendLine("onDblClickRow:function(rowIndex, row){");
        JsBuilder.AppendLine(" if (row[\"XML_AH\"]==\"\") return;");
        JsBuilder.AppendLine(" OpenCase(row[\"XML_AH\"],row[\"XML_FYDM\"],row[\"XML_AHZT\"]);");
        JsBuilder.AppendLine("}");
        EasyUIDataGridIntialData = JsBuilder.ToString();
    }


    protected void button_ExportExcel_Click(object sender, EventArgs e)
    {

        string nowStr = DateTime.Now.ToString("yyyMMddhhmmss");
        //定义文档类型、字符编码
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        //下面这行很重要， attachment 参数表示作为附件下载，您可以改成 online在线打开
        //filename=FileFlow.xls 指定输出文件的名称，注意其扩展名和指定文件类型相符，可以为：.doc 　　 .xls 　　 .txt 　　.htm
        Response.AppendHeader("Content-Disposition", string.Format("attachment;filename=({0}).xls", nowStr));
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        //Response.ContentType指定文件类型 可以为application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他浏览器可直接支持文档
        Response.ContentType = "application/ms-excel";
        this.EnableViewState = false;
        ////　定义一个输入流
        //System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        //System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

        //this.RenderControl(oHtmlTextWriter);
        ////this 表示输出本页，你也可以绑定datagrid,或其他支持obj.RenderControl()属性的控件
        PaginationDataLister lister = new PaginationDataLister(WebPageName, Request, Session);
        DataTable dt = lister.dataList.GetTotalData();

        Response.Write(Tools.DataTabletoExcel(dt, DataGirdColumns));
        Response.End();
    }
}
